/** 
 * @author seeker910
 * @description redjs javascript sdk :cms-api.js
 * @description 网站相关api 接口
 */ 

var cmsHost = {
    text:'cms C端服务',
    name:'cms',
    url:'http://cms.sellerpartner.cn/',  
    index:'dev/index',
    isLoaded:false,
    useSSL:false,
    controllers:[ 
        {name:'news',path:'news',GetDescription:'GetDes'}, 
        {name:'blog',path:'blog',GetDescription:'GetDes'},
        {name:'interact',path:'interact',GetDescription:'GetDes'},
        {name:'content',path:'content',GetDescription:'GetDes'},
    ]
};
var apiConfig = [
    {
        "group": "cms.news",
        "errorHandler":  Rsd.app.httpRequestErrorHandler,
        "failureHandler": "failureHandler",
        "successHandler": null,
        "api": [ 
            {
                "name": "upload",
                "failureHandler": "uploadFailHandler",
                "successHandler": "uploadSccessHandler",
                "method": "POST",
                //timeout:10000
            }

        ]
    },

];
/**
* 加载api services
*/
Rsd.loadServices(cmsHost,[],function(data,state){ 
   
   if(state=='serviceLoaded')
   {
        rsd.app.fire('cms-api',data);
   }
});
//缓存数据
$app.cms = $app.cms||{};


/**
 * 提交订阅
 * @param {*} form 
 */
$app.cms.submitSubscribe = function submitSubscribe(data,callback)
{ 
    if (Rsd.isEmpty(data['email'])) { 
        callback && callback({success:false,msg:'The email field is required.'});
        return false;
    }
    if (Rsd.isEmpty(data['subject'])) {
        callback && callback({success:false,msg:'The subject field is required.'});
        return false;
    } 
    $app.submitData("cms.interact.subscribe",data,callback);
}
/**
 * 提交联系我们信息
 * @param {*} form 
 */
$app.cms.submitContact = function submitContact(data,callback)
{  
    if (Rsd.isEmpty(data['company'])) {
        callback && callback({success:false,msg:'The company field is required.'}); 
        return false;
    }
    if (Rsd.isEmpty(data['name'])) {
        callback && callback({success:false,msg:'The name field is required.'}); 
        return false;
    }
    if (Rsd.isEmpty(data['email'])) {
        callback &&  callback({success:false,msg:'The email field is required.'}); 
        return false;
    }
    if (Rsd.isEmpty(data['phone'])) {
        callback && callback({success:false,msg:'The phone field is required.'}); 
        return false;
    }
    if (Rsd.isEmpty(data['message'])) {
        callback && callback({success:false,msg:'The message field is required.'}); 
        return false;
    }
    $app.submitData("cms.interact.contact",data,callback);
}
/**
 * 全文搜索
 * @param {*} form 
 */
$app.cms.submitSearch = function submitSearch(data,callback)
{ 
    $app.submitData("cms.search.text",data,callback);//
}